package com.example.neusoft215gdh.androidpro_21.Activity;

import android.content.Intent;
import android.net.Uri;
import android.os.Bundle;
import android.support.v7.app.AppCompatActivity;
import android.view.View;
import android.widget.Button;
import android.widget.ImageView;
import android.widget.TextView;

import com.example.neusoft215gdh.androidpro_21.JavaBean.Activitys;
import com.example.neusoft215gdh.androidpro_21.Listener.ActivityDetailListener;
import com.example.neusoft215gdh.androidpro_21.Model.ActivityModel;
import com.example.neusoft215gdh.androidpro_21.R;
import com.squareup.picasso.Picasso;

public class ActivityDetailActivity extends AppCompatActivity implements ActivityDetailListener,View.OnClickListener{


    private ImageView img;
    private TextView name,intro,time,place,price,tel,num;
    private Button baoming;
    Intent intent;
    public  String Picid;
    public int id;
    public Activitys list;
    ImageView reg_return;
    String acname,acprice,notice,telephone;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_detail);
        intent=getIntent();
        Picid=intent.getStringExtra("id");
        ActivityModel activityModel=new ActivityModel();
        activityModel.getActivityById(Picid,this);
        initViews();
        baoming.setOnClickListener(this);
        reg_return.setOnClickListener(this);
        tel.setOnClickListener(this);
    }

    public void initViews() {
        img= (ImageView) findViewById(R.id.img);
        intro= (TextView) findViewById(R.id.intro);
        name= (TextView) findViewById(R.id.name);
        time= (TextView) findViewById(R.id.time);
        place= (TextView) findViewById(R.id.place);
        price= (TextView) findViewById(R.id.price);
        tel= (TextView) findViewById(R.id.tel);
        num= (TextView) findViewById(R.id.hits);
        baoming= (Button) findViewById(R.id.baoming);
        reg_return= (ImageView) findViewById(R.id.reg_return);
    }

    @Override
    public void onResponse(Activitys bean) {
        list=bean;
        telephone=list.getContact_tel();
        acname=list.getActivity_name();
        acprice=list.getActivity_price();
        notice=list.getNotice();

        intro.setText(list.getIntroduction());
        name.setText(list.getActivity_name());
        time.setText(list.getStart_date());
        place.setText(list.getPlace());
        price.setText(list.getActivity_price());
        num.setText(list.getHits());
        tel.setText(telephone);
        if(!list.getThumb().isEmpty())
        {
            Picasso.with(this).load("http://172.24.10.175/workout/Uploads/"+list.getThumb()).into(img);
        }
        else
        {
            img.setImageResource(R.drawable.ic_me);
        }
    }

    @Override
    public void onFail(String msg) {

    }

    @Override
    public void onClick(View v) {
        switch (v.getId()){
            case R.id.tel:
                Intent inten = new Intent(Intent.ACTION_DIAL, Uri.parse("tel:" + telephone));
                inten.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
                startActivity(inten);
                break;
            case R.id.baoming:
                Intent intent=new Intent(ActivityDetailActivity.this, ActivityOrderActivity.class);
                intent.putExtra("activity_id",list.getId());
                intent.putExtra("activity_name",acname);
                intent.putExtra("activity_price",acprice);
                intent.putExtra("activity_notice",notice);
                startActivity(intent);
                break;
            case R.id.reg_return:
                finish();

        }
    }
}
